package com.zsy.rocketdemo.produce;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.springframework.stereotype.Component;

@Component
public class ZsyAsyncProdecer extends BaseProducer {
    public ZsyAsyncProdecer() {
        tag = "zsyAsyn";
    }

    @Override
    public void sendMessage(Message message) throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
        super.producer.send(message, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                System.out.printf("%s OK  %n", sendResult.getMsgId());
            }

            @Override
            public void onException(Throwable e) {
                System.out.printf("%s Exception %n", e);
                e.printStackTrace();
            }
        });

    }
}
